package com.example.mcp.server.config;

/**
 * @author ssk
 * @date 2025/8/8
 **/

import com.example.mcp.server.service.McpService;
import com.example.mcp.server.service.handler.McpWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private McpService mcpService;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new McpWebSocketHandler(), "/mcp")
                .setAllowedOrigins("*"); // 生产环境应该配置具体的域名
    }

    @Bean
    public McpWebSocketHandler mcpWebSocketHandler() {
        return new McpWebSocketHandler();
    }

}